<template>
  <div>
    <div>{{ teacher.name }}</div>
    <div>{{ teacher.age }}</div>
    <div>{{ teacher.salary }}</div>
    <button @click="btn">过了一年</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      teacher: {
        name: 'harry',
        age: 28,
        salary: 3000,
      },
    }
  },
  computed: {},
  watch: {
    // // 监视小花的年纪
    // 'teacher.age' (newVal, oldVal) {
    //   if(newVal===40) alert("您该退休了"+"您的年纪是"+this.teacher.age+"您的工资是"+this.teacher.salary)
    //   console.log('老师，你变了，年纪:'+ newVal+'薪水：'+this.teacher.salary, '之前：', oldVal)
    // }
    "teacher.age"(newVal, oldVal) {
      if (newVal === 40)
        alert(
          '您该退休了' +
            '您的年纪是' +
            this.teacher.age +
            '您的工资是' +
            this.teacher.salary,
          '之前：',
          oldVal
        )
    },
  },

  methods: {
    btn() {
      this.teacher.age += 1
      this.teacher.salary += 500
    },
  },
}
</script>

<style scoped></style>
